package com.bjmashibing.system.OSFileIO.io_demo.InputOrOutput;

import java.io.*;

public class OutputStreamDemo {
    public static void main(String[] args) throws IOException {
//        demo1();
        demo2();
    }

    /**
     *
     * @throws IOException
     */
    public static void demo1()throws IOException{
        File file= new File("src/Java_IO/io_demo/Resources/aaa.txt");
        OutputStream outputStream=new FileOutputStream(file);
        outputStream.write(99);
        outputStream.write("\r\ndavid".getBytes());
        outputStream.close();

    }

    /**
     * 需求：将abc.txt中的数据写入到aaa.txt中
     */
    public static void demo2() throws IOException {
        File file1=new File("src/Java_IO/io_demo/Resources/abc.txt");
        File file2= new File("src/Java_IO/io_demo/Resources/aaa.txt");
        FileInputStream inputStream = new FileInputStream(file1);
        FileOutputStream outputStream = new FileOutputStream(file2);
        byte[] buffer=new byte[26];
        int length=Integer.MIN_VALUE;
        while ((length=inputStream.read(buffer))!=-1){
            outputStream.write(buffer);
        }
        outputStream.close();
        inputStream.close();
    }


}
